<template>
  <div style="width: 100%">
    <a-card class="card" :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="院系">
                <a-select
                  :disabled="selectYxConfig.length === 1" 
                  :allowClear="true"
                  showSearch
                  optionFilterProp="children"
                  v-model="queryParam.yx"
                  @change="handleSelectYx"
                >
                  <a-select-option
                    v-for="i in selectYxConfig"
                    :key="i.dwh"
                    :value="i.dwh"
                  >{{ i.dwh+'-'+i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
              <a-form-item label="专业">
                <a-select
                  :allowClear="true"
                  showSearch
                  optionFilterProp="children"
                  v-model="queryParam.zy"
                >
                  <a-select-option
                    v-for="i in selectZyConfig"
                    :key="i.zyh"
                    :value="i.zyh"
                  >{{ i.zyh+'-'+i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <template v-if="advanced">
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="学生类别">
                  <a-select
                    :allowClear="true"
                    showSearch
                    optionFilterProp="children"
                    v-model="queryParam.xslbm"
                  >
                    <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item
                  label="学生来源"
                >
                  <a-select :allowClear="true" v-model="queryParam.xslxm">
                    <a-select-option v-for="i in TYPE0503" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="姓名">
                  <a-input v-model="queryParam.xm" />
                </a-form-item>
              </a-col>
            </template>
            <a-col :sm="{span:24}" :xl="{span:advanced?24:12}" style="text-align:center">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button type="primary" @click="handleExport">打印表决票</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'" />
              </a>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card class="card" :bordered="false">
      <STable
        v-if="init"
        ref="table"
        rowKey="index"
        size="default"
        :columns="columns"
        :data="loadData"
        :alert="{ show: true }"
        :scroll="{ x: 1300 }"
      >
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <span
          slot="jswyhyj"
          slot-scope="text, record, index"
        >{{ record.wyhTyps }}同{{ record.wyhFdps }}反{{ record.wyhQqps }}弃</span>
      </STable>
    </a-card>
  </div>
</template>

<script>
// import moment from 'moment'
import { STable } from "~";
import { mapState } from "vuex";

const selectArr = [
  "TYPE0075" //学生类别
];

export default {
  components: {
    STable
  },
  data() {
    return {
      advanced: true,
      //条件配置
      selectYxConfig: [], //院系
      selectZyConfig: [], //专业
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: "序号",
          scopedSlots: { customRender: "serial" }
        },
        {
          title: "姓名",
          dataIndex: "xm"
        },
        {
          title: "专业",
          dataIndex: "sszymc"
        },
        {
          title: "申请学位类别",
          dataIndex: "sqxwlb"
        },
        {
          title: "指导老师",
          dataIndex: "dsxm"
        },
        // {
        //   title: '应修学分',
        //   dataIndex: 'jhzxf'
        // },
        // {
        //   title: '实修学分',
        //   dataIndex: 'yxzxf'
        // },
        {
          title: "论文评阅成绩",
          children: [
            {
              title: "A",
              dataIndex: "lwyx"
            },
            {
              title: "B",
              dataIndex: "lwlh"
            },
            {
              title: "C",
              dataIndex: "lwyb"
            }
            // {
            //   title: '不及格',
            //   dataIndex: 'lwbjg'
            // },{
            //   title: '通过率',
            //   dataIndex: 'lwpytgl'
            // }
          ]
        },
        {
          title: "答辩成绩",
          children: [
            {
              title: "优秀",
              dataIndex: "dbyx"
            },
            {
              title: "良好",
              dataIndex: "dblh"
            },
            {
              title: "一般",
              dataIndex: "dbyb"
            },
            {
              title: "不及格",
              dataIndex: "dbbjg"
            },
            {
              title: "通过率",
              dataIndex: "dbcjtgl"
            }
          ]
        },
        {
          title: "教授委员会意见",
          dataIndex: "jswyhyj",
          scopedSlots: { customRender: "jswyhyj" }
        },
        {
          title: "学部会审核意见",
          // dataIndex: "shjgmc"
          //scopedSlots: { customRender: 'xbhssyj' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo;
        let params = Object.assign(this.queryParam, parameter);
        return this.$api.degree.auditDivisionVote(params).then(res => {
          let list = res.data.rows;
          list.map(e => {
            let lwthrough = e.lwyx + e.lwlh + e.lwyb;
            let lwCount = lwthrough + e.lwbjg;
            let dbthrough = e.dbyx + e.dblh + e.dbyb;
            let dbCount = dbthrough + e.dbbjg;
            e.dbcjtgl = `${dbthrough}/${dbCount}`; //Math.round((e.dbyx+e.dblh+e.dbyb)/dbCount*10000)/100.00+'%';
            e.lwpytgl = `${lwthrough}/${lwCount}`; //Math.round((e.lwyx+e.lwlh+e.lwyb)/lwCount*10000)/100.00+'%';
          });
          return {
            data: list,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          };
        });
      },
      init: false
    };
  },
  computed: {
    ...mapState({
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0075: state => state.app["TYPE0075"] // 学生类别
    })
  },
  created() {
    this.initSelectMenu();

    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    selectArr.forEach(v => {
      this.$store.dispatch("app/setDictionary", v);
    });
  },
  methods: {
    initSelectMenu() {
      let allRequest = [this.$api.base.collegeAll()];
      Promise.all(allRequest).then(res => {
        this.selectYxConfig = res[0].data;
        if (res[0].data.length === 1) {
          this.$set(this.queryParam, 'yx', res[0].data[0].dwh)
          this.handleSelectYx(res[0].data[0].dwh)
        }
        this.init = true
      });
    },
    //选择院系
    handleSelectYx(code) {
      this.selectZyConfig = [];
      this.$set(this.queryParam, "zy", "");
      this.$api.base.majorAll({ lsdwh: code }).then(res => {
        this.selectZyConfig = res.data;
      });
    },
    // 打印
    handleExport() {
      if (this.queryParam.yx == "" || !this.queryParam.yx) {
        this.$notification["error"]({
          message: "错误提示",
          description: "请选择所属院系！"
        });
        return;
      }
      // if (this.queryParam.zy==''||!this.queryParam.zy) {
      //   this.$notification['error']({
      //     message: '错误提示',
      //     description: '请选择所属专业！',
      //   });
      //   return;
      // }
      if (this.queryParam.xslbm == "" || !this.queryParam.xslbm) {
        this.$notification["error"]({
          message: "错误提示",
          description: "请选择学生类别！"
        });
        return;
      }
      this.$export("/degree/xwsh/xbhbjpPrint", this.queryParam);
    }
  }
};
</script>

<style lang="less" scoped>
.card {
  margin-bottom: 20px;
}
</style>
